<?php

namespace Model;
use Think\Model;
//为sw_role数据表创建一个Model模型类
//父类model：Think/library/think/model.class.php
class RoleModel extends Model{
    //制作数据，存储数据$role_auth_ids,$role_auth_ac
    function saveAuth($roleid,$authid){

        //1.制作role_auth_ids
        $authids = implode(',',$authid);
//        dump($authids);

        //2.制作role_auth_ac(控制器和操作方法连接的字符串)
        //根据把选中的权限id 信息，查询对应权限记录，遍历并获得每个权限的controller和action信息
        $authinfo = D('Auth')->select($authids);
        $s = "";
        foreach($authinfo as $k => $v){
            if(!empty($v['auth_a'])&&!empty($v['auth_c'])){
                $s .=$v['auth_c']."-".$v['auth_a'].",";
            }
        }
        $s = rtrim($s,",");
//        dump($s);

        $sql = "update sw_role set role_auth_ids='$authids',role_auth_ac='$s' where role_id = '$roleid'";
        //$this代表的调用该方法的当前对象，$role
        return $this->execute($sql);

    }

}